package com.sec.typhoondatapush.init;

import com.sec.typhoondatapush.entity.JobConfig;
import com.sec.typhoondatapush.repository.JobConfigRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 初始化数据服务（产生一个默认的定时任务的配置）
 *
 * @author zhuwq
 * @date 2018-08-03
 */
@Service
@Slf4j
public class InitService {

    @Autowired
    private JobConfigRepository jobConfigRepository;

    public void init() {
        // if no initial record exists, then create one.
        if (jobConfigRepository.findAll().size() <= 0) {
            JobConfig jobConfig = new JobConfig();
            jobConfig.setName("sina_stock_crawl_task");
            jobConfig.setGroup("gr1");
            jobConfig.setClassPath("com.sec.typhoondatapush.service.task.ScheduleTask");
            jobConfig.setMethodName("task1");
            jobConfig.setStatus("0");
            jobConfig.setCron("0 0/1 * * * ? ");
            jobConfigRepository.save(jobConfig);
            log.info("job_config database initialization initial record inserted.");
        }
        log.info("job_config database initialization completed.");
    }
}
